unit unitIni;

interface

uses
  Classes, SysUtils, IniFiles, Forms, Windows;

const
  csIniWebServeInfoSection = 'WebServeInfo';

  {Section: WebServeInfo}
  csIniWebServeInfoURL = 'URL';
  csIniWebServeInfoPort = 'Port';
  csIniWebServeInfoFilters = 'Filters';

type
  TIniOptions = class(TObject)
  private
    {Section: WebServeInfo}
    FWebServeInfoURL: string;
    FWebServeInfoPort: Integer;
    FWebServeInfoFilters: string;
  public
    procedure LoadSettings(Ini: TIniFile);
    procedure SaveSettings(Ini: TIniFile);

    procedure LoadFromFile(const FileName: string);
    procedure SaveToFile(const FileName: string);

    {Section: WebServeInfo}
    property WebServeInfoURL: string read FWebServeInfoURL write FWebServeInfoURL;
    property WebServeInfoPort: Integer read FWebServeInfoPort write FWebServeInfoPort;
    property WebServeInfoFilters: string read FWebServeInfoFilters write FWebServeInfoFilters;
  end;

var
  IniOptions: TIniOptions = nil;

implementation

procedure TIniOptions.LoadSettings(Ini: TIniFile);
begin
  if Ini <> nil then
  begin
    {Section: WebServeInfo}
    FWebServeInfoURL := Ini.ReadString(csIniWebServeInfoSection, csIniWebServeInfoURL, 'http://localhost/');
    FWebServeInfoPort := Ini.ReadInteger(csIniWebServeInfoSection, csIniWebServeInfoPort, 80);
    FWebServeInfoFilters := Ini.ReadString(csIniWebServeInfoSection, csIniWebServeInfoFilters, '~*.*,*.tmp,');
  end;
end;

procedure TIniOptions.SaveSettings(Ini: TIniFile);
begin
  if Ini <> nil then
  begin
    {Section: WebServeInfo}
    Ini.WriteString(csIniWebServeInfoSection, csIniWebServeInfoURL, FWebServeInfoURL);
    Ini.WriteInteger(csIniWebServeInfoSection, csIniWebServeInfoPort, FWebServeInfoPort);
    Ini.WriteString(csIniWebServeInfoSection, csIniWebServeInfoFilters, FWebServeInfoFilters);
  end;
end;

procedure TIniOptions.LoadFromFile(const FileName: string);
var
  Ini: TIniFile;
begin
  if FileExists(FileName) then
  begin
    Ini := TIniFile.Create(FileName);
    try
      LoadSettings(Ini);
    finally
      Ini.Free;
    end;
  end;
end;

procedure TIniOptions.SaveToFile(const FileName: string);
var
  Ini: TIniFile;
begin
  Ini := TIniFile.Create(FileName);
  try
    SaveSettings(Ini);
  finally
    Ini.Free;
  end;
end;

initialization
  IniOptions := TIniOptions.Create;

finalization
  IniOptions.Free;

end.

